
*********** This program generates Figure A-1, A-2, and A-3 of the appendix ***********

clear all
set more off
set scheme s1mono

cd "$localdir/Data"
gl output "$localdir/Output"


*** Load analysis data
use msa_survey_indiv, clear

* MSA evaluation
g msa_got_worse=(changes_msa_worse==4 | changes_msa_worse==5) if changes_msa_worse!=.
lab var msa_got_worse "MSA Economy Got Worse"

* Save data used to generate bar graphs data
save local_national_data, replace



*** Generate bar graphs data

use local_national_data, clear

g total=_N
bysort imp_perf_factor_localecpolicy: g local_total=_N
g localshare=local_total/total

g scale=1 if imp_perf_factor_localecpolicy==1
replace scale=2 if imp_perf_factor_localecpolicy==2
replace scale=3 if imp_perf_factor_localecpolicy==3
replace scale=4 if imp_perf_factor_localecpolicy==4

keep scale localshare
duplicates drop scale,force

save local, replace


use local_national_data, clear
keep if msa_got_worse==0

g total=_N
bysort imp_perf_factor_localecpolicy: g local_total=_N
g localshare_better=local_total/total

g scale=1 if imp_perf_factor_localecpolicy==1
replace scale=2 if imp_perf_factor_localecpolicy==2
replace scale=3 if imp_perf_factor_localecpolicy==3
replace scale=4 if imp_perf_factor_localecpolicy==4

keep scale localshare_better
duplicates drop scale,force

save local_better, replace


use local_national_data, clear
keep if msa_got_worse==1

g total=_N
bysort imp_perf_factor_localecpolicy: g local_total=_N
g localshare_worse=local_total/total

g scale=1 if imp_perf_factor_localecpolicy==1
replace scale=2 if imp_perf_factor_localecpolicy==2
replace scale=3 if imp_perf_factor_localecpolicy==3
replace scale=4 if imp_perf_factor_localecpolicy==4

keep scale localshare_worse
duplicates drop scale,force

save local_worse, replace


use local_national_data, clear

g total=_N
bysort imp_perf_factor_nationalecpolicy: g national_total=_N
g nationalshare=national_total/total

g scale=1 if imp_perf_factor_nationalecpolicy==1
replace scale=2 if imp_perf_factor_nationalecpolicy==2
replace scale=3 if imp_perf_factor_nationalecpolicy==3
replace scale=4 if imp_perf_factor_nationalecpolicy==4

keep scale nationalshare
duplicates drop scale, force

save national, replace


use local_national_data, clear
keep if msa_got_worse==0

g total=_N
bysort imp_perf_factor_nationalecpolicy: g national_total=_N
g nationalshare_better=national_total/total

g scale=1 if imp_perf_factor_nationalecpolicy==1
replace scale=2 if imp_perf_factor_nationalecpolicy==2
replace scale=3 if imp_perf_factor_nationalecpolicy==3
replace scale=4 if imp_perf_factor_nationalecpolicy==4

keep scale nationalshare_better
duplicates drop scale, force

save national_better, replace


use local_national_data, clear
keep if msa_got_worse==1

g total=_N
bysort imp_perf_factor_nationalecpolicy: g national_total=_N
g nationalshare_worse=national_total/total

g scale=1 if imp_perf_factor_nationalecpolicy==1
replace scale=2 if imp_perf_factor_nationalecpolicy==2
replace scale=3 if imp_perf_factor_nationalecpolicy==3
replace scale=4 if imp_perf_factor_nationalecpolicy==4

keep scale nationalshare_worse
duplicates drop scale, force

save national_worse, replace


use national, clear
merge 1:1 scale using national_better
drop _merge
merge 1:1 scale using national_worse
drop _merge
merge 1:1 scale using local
drop _merge
merge 1:1 scale using local_better
drop _merge
merge 1:1 scale using local_worse
drop _merge

lab def scale 1 "Not Important" 2 "Of Little Importance" 3 "Somewhat Important" 4 "Very Important"
lab val scale scale

foreach x of varlist nationalshare localshare {
replace `x'=`x'*100
replace `x'_better=`x'_better*100
replace `x'_worse=`x'_worse*100
}


*** Generate bar graphs

graph bar nationalshare localshare, over(scale, lab(labsize(small)) gap(80)) ///
bar(1, color(midblue)) bar(2, color(ltblue)) bargap(0) ///
legend(lab(1 "National Economic Policies") lab(2 "Local Economic Policies") ///
region(fcolor(white) lcolor(white)) size(small) cols(2) symx(*0.5) symy(*0.5) keyg(*0.8) colg(5)) graphregion(color(white) margin(l=5)) ///
title("", size(medium) margin(b+3)) ///
yscale(titlegap(*5)) ytitle("Respondents (%)") ylabel(0 (20) 60) 

graph export "$output/figA1.pdf", replace
graph export "$output/figA1.eps", replace


graph bar nationalshare_better localshare_better, over(scale, lab(labsize(small)) gap(80)) ///
bar(1, color(midblue)) bar(2, color(ltblue)) bargap(0) ///
legend(lab(1 "National Economic Policies") lab(2 "Local Economic Policies") ///
region(fcolor(white) lcolor(white)) size(small) cols(2) symx(*0.5) symy(*0.5) keyg(*0.8) colg(5)) graphregion(color(white) margin(l=5)) ///
title("", size(medium) margin(b+3)) ///
yscale(titlegap(*5)) ytitle("Respondents (%)") ylabel(0 (20) 60) 

graph export "$output/figA2.pdf", replace
graph export "$output/figA2.eps", replace


graph bar nationalshare_worse localshare_worse, over(scale, lab(labsize(small)) gap(80)) ///
bar(1, color(midblue)) bar(2, color(ltblue)) bargap(0) ///
legend(lab(1 "National Economic Policies") lab(2 "Local Economic Policies") ///
region(fcolor(white) lcolor(white)) size(small) cols(2) symx(*0.5) symy(*0.5) keyg(*0.8) colg(5)) graphregion(color(white) margin(l=5)) ///
title("", size(medium) margin(b+3)) ///
yscale(titlegap(*5)) ytitle("Respondents (%)") ylabel(0 (20) 60) 

graph export "$output/figA3.pdf", replace
graph export "$output/figA3.eps", replace















